export default {
  state: {
    text: "我是user模块下state.text的值",
    //手机号
    phoneNumber: uni.getStorageSync('phoneNumber') || '',
    countryCode: uni.getStorageSync('countryCode') || '',
    purePhoneNumber: uni.getStorageSync('purePhoneNumber') || '',
    openId: uni.getStorageSync('openId') || '',
    unionId: uni.getStorageSync('unionId') || '',
    userInfo: !!uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {},
    userInfoFull: !!uni.getStorageSync('userInfoFull') ? JSON.parse(uni.getStorageSync('userInfoFull')) : {},
    userId: uni.getStorageSync('userId') || '' // 支付宝
  },
  getters: {
    getText(state) {
      return 12
    }
  },
  mutations: {
    updateText(state) {
      console.log(12222222)
      console.log(state)
    },
    updatePhoneNumber(state, phoneNumber) {
      uni.setStorageSync('phoneNumber', phoneNumber);
      state.phoneNumber = phoneNumber
    },
    updateCountryCode(state, countryCode) {
      uni.setStorageSync('countryCode', countryCode);
      state.countryCode = countryCode
    },
    updatePurePhoneNumber(state, purePhoneNumber) {
      uni.setStorageSync('purePhoneNumber', purePhoneNumber);
      state.purePhoneNumber = purePhoneNumber
    },
    updateOpenId(state, openId) {
      uni.setStorageSync('openId', openId);
      state.openId = openId
    },
    updateUnionId(state, unionId) {
      uni.setStorageSync('unionId', unionId);
      state.unionId = unionId
    },
    updateUserId(state,userId){
      uni.setStorageSync('userId', userId);
      state.userId = userId
    },
    clearUserAuthen(state){
      uni.removeStorageSync('phoneNumber')
      uni.removeStorageSync('countryCode')
      uni.removeStorageSync('purePhoneNumber')
      uni.removeStorageSync('openId')
      uni.removeStorageSync('unionId')
      uni.removeStorageSync('userId')
      state.phoneNumber = ''
      state.countryCode = ''
      state.purePhoneNumber = ''
      state.openId = ''
      state.unionId = ''
      state.userId = ''
    },

    // 用户基本信息
    updateUserInfo(state, userInfo) {
      uni.setStorageSync('userInfo', JSON.stringify(userInfo));
      state.userInfo = userInfo
    },
    // 用户的所有信息
    updateuserInfoFull(state,userInfoFull){
      let info = {...state.userInfo,...userInfoFull}
      uni.setStorageSync('userInfoFull', JSON.stringify(info));
      state.userInfoFull = info
    },
    clearUserInfo(state) {
      uni.removeStorageSync('userInfo')
      state.userInfo = {}
    },

  },
  actions: {

  }
}
